package com.shr.codem;

import java.util.Scanner;

public class Music1 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int count1 = sc.nextInt();
		int[] aArray = new int[count1];
		for(int i = 0;i<count1;i++){
			aArray[i] = sc.nextInt() ;
		}
		
		int count2 = sc.nextInt() ;
		int[] bArray = new int[count2] ;
		for(int i = 0;i<count2;i++){
			bArray[i] = sc.nextInt() ;
		}
		
		int minValue = Integer.MAX_VALUE ;
		for(int i = 0;i<bArray.length - aArray.length + 1 ;i++){
			int diff = 0;
			for(int j = 0;j<aArray.length;j++){
				diff += Math.pow(bArray[i+j]-aArray[j], 2.0) ;
			}
			if(diff < minValue)
				minValue = diff ;
		}
		System.out.println(minValue);
		sc.close();
		
	}
}
